package net.zjitc.homework.homework11;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

/**
 * @author 李广彦
 * @date 2019-04-25-17：05
 */
public class BookPreparedStatementUpdateTest {
    public static void main(String[] args) {
        Scanner scannerInt=new Scanner(System.in);
        Connection conn=null;
        PreparedStatement pstmt=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/library";
            String user="root";
            String password="985211";
            conn= (Connection) DriverManager.getConnection(url,user,password);
            String sql="update book set ?=? where bookid=?";
            pstmt=conn.prepareStatement(sql);
            System.out.println("请输入要修改的图书id：");
            int bookid=scannerInt.nextInt();
            int s=pstmt.executeUpdate();
            System.out.println("影响了"+s+"行");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (pstmt!=null){
                    pstmt.close();
                }
                if (conn!=null){
                    conn.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
